<?php

require_once dirname(__FILE__) . "/../includes/config.php";
require_once PHP_ROOTPATH.'/classes/database.php';

//récupération des nom de test dans la base de données
header("Content-Type: text/xml; charset=utf-8");
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
echo "<list>";
 
$label = (isset($_POST["label"])) ? html_entity_decode($_POST["label"]) : NULL;

if($label){
	$idconnect = Database::getInstance();

	if($label=="Test comportemental"){
		$query = "SELECT DISTINCT(description) as type FROM Type_test WHERE description NOT LIKE '%Test open-field%' AND description NOT LIKE 'Novel object' 
		AND description NOT LIKE 'Pairwise discrimination' AND description NOT LIKE 'Pairwise inversion' AND description NOT LIKE 'Questionnaire' 
		AND label='Test comportemental' ORDER BY description";
	}
	else if($label=="Test biologique"){
		$query = "SELECT DISTINCT(unite_mesure) as type FROM Type_test WHERE label='Test biologique' ORDER BY unite_mesure";
	}
	$res_query = pg_query($idconnect , $query) or die(pg_last_error());
    while ($back = pg_fetch_assoc($res_query)) {
		if($back["type"]=="Discrimination"){
			echo "<item id=\"Discrimination/inversion\" name=\"Discrimination/inversion\" />\n";
		}
		else if($back["type"]=="Hourglass narrow"){
			echo "<item id=\"Hourglass\" name=\"Hourglass\" />\n";
		}
		else if($back["type"]!="Inversion" and $back["type"]!="Hourglass wide"){
			echo "<item id=\"" . $back["type"] . "\" name=\"" . $back["type"]. "\" />\n";
		}
    }
}
echo "</list>";
?>
